package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.UserOrderAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserOrderBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetUserOderListModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class OrderFiveFragment extends BaseFragment implements View.OnClickListener {
    EmptyRecyclerView order_five_rv;
    private List<UserOrderBean> items;
    View orderfive_ev;
    TextView tv_message;

    @Override
    public void onClick(View view) {

    }

    @Override
    void initView() {
        order_five_rv = (EmptyRecyclerView) view.findViewById(R.id.order_five_rv);
        orderfive_ev = (View)view.findViewById(R.id.orderfive_ev);
        tv_message = (TextView)view.findViewById(R.id.tv_message);

        GetUserOderListModel getUserOderListModel = new GetUserOderListModel();
        getUserOderListModel.getUserAllOrderList(getid(),orderBeanListListener);
    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }

    public OrderFiveFragment() {
        // Required empty public constructor
    }

    ListListener<UserOrderBean> orderBeanListListener = new ListListener<UserOrderBean>() {
        @Override
        public void onResponse(List<UserOrderBean> list) {
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            order_five_rv.setLayoutManager(linearLayoutManager);
            items=list;
            UserOrderAdapter userOrderAdapter=new UserOrderAdapter(getContext(),items,R.layout.userorder_item);
            order_five_rv.setAdapter(userOrderAdapter);
            order_five_rv.setItemAnimator(new DefaultItemAnimator());
            order_five_rv.setEmptyView(orderfive_ev);
            tv_message.setText("你还没有订单，赶紧去下单购买东西吧");
        }

        @Override
        public void onFail(String msg) {

        }
    };


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_order_five);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

}
